<template>
  <div class="answer-container">
    <el-form label-width="0" size="small" v-loading="loading">
      <el-form-item>
        <el-input
          type="textarea"
          :rows="8"
          v-model="textareaContent">
        </el-input>

        <el-button type="success" size="small" style="margin-left: 10px" @click="handlerInsert">
          插入
        </el-button>

        <el-button type="success" size="small" style="margin-left: 10px" @click="handleReplace">
          替换
        </el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import {
  modelSettingFirstChat,
  modelSettingChat,
} from "@/api/aiccApi/aiccLargeModel";
export default {
  data(){
    return{
      textareaContent:'',
      loading:false,
    }
  },
  props:{
    content:{
      type:String,
      default:""
    },
  },

  mounted(){
    this.getFirstChat();
  },

  methods:{
    //进行首次问答
    getFirstChat(){
      const info = {
        type:2,
        status:1,
        content: this.content,
      };
      this.loading = true;
      modelSettingFirstChat(info).then(res=>{
        if(res.data.code == 200){
          this.loading = false;
          var Data = res.data.data;
          Data = Data.replace(/^"|"$/g, '');
          Data = Data.replace(/\\(\\)?n/g, '\n');
          this.textareaContent = Data.replace(/\n/g, '<br>');
        }
      })
    },

    //重新生成答案
    handlerReBuild(val){
      const info = {
        modelId:val.largeModel,
        promatId:val.tipWord,
        pattern:val.mode,
        content:this.content,
        top:'',
        temperature:''
      };
      this.loading = true;
      modelSettingChat(info).then(res=>{
        if(res.data.code == 200){
          this.textareaContent = '';
          this.loading = false;
          var Data = res.data.data;
          Data = Data.replace(/^"|"$/g, '');
          Data = Data.replace(/\\(\\)?n/g, '\n');
          this.textareaContent = Data.replace(/\n/g, '<br>')
        }
      })
    },

    //插入
    handlerInsert(){
      this.$emit('handlerInsert',this.textareaContent)
    },

    //替换
    handleReplace(){
      this.$emit('handlerReplace',this.textareaContent)
    },

  },
}
</script>

<style scoped lang="scss">
.answer-container{
  max-height: 400px;
  /deep/ .el-form-item__content{
    display: flex;
    align-items: center;
  }
}
</style>
